# ~/.config/rust-env.sh
#!/bin/bash

rust_bin="/opt/rust/.cargo/bin"

use_central_rust() {
    export RUSTUP_HOME=/opt/rust/.rustup
    export CARGO_HOME=/opt/rust/.cargo
    if [[ ":$PATH:" != *":$rust_bin:"* ]]; then
        export PATH="$rust_bin:$PATH"
    fi
    echo "Using central Rust at /opt/rust"
}

# 可选：提供一个重置回系统 Rust 的函数
use_system_rust() {
    unset RUSTUP_HOME
    unset CARGO_HOME
    # 从 PATH 中移除 /opt/rust/.cargo/bin（简单做法：重新加载原始 PATH）
    # 更健壮的做法需要保存原始 PATH，但对个人使用，重启 shell 或手动调整即可
    if [[ ":$PATH:" == *":$rust_bin:"* ]]; then
        PATH=":$PATH:"
        PATH="${PATH//:$rust_bin:/:}"
        PATH="${PATH/#:$rust_bin:/:}"
        PATH="${PATH/$:$rust_bin:/:}"
        PATH="${PATH#:}"
        PATH="${PATH%:}"
    fi
    echo "Reverting to system Rust (restart shell or adjust PATH manually)"
}
